<?php
/**
 * Serveur REST de l'applicaiton
 *
 * @package zfbook
 * @subpackage reservation
 */
class Zfbook_Reservation_RestServer extends Zfbook_Reservation_Server
{
    const STATUS_SUCCESS = 'success';
    const STATUS_FAIL    = 'fail';
    
    /**
     * Personnalisation de getRoom en XML pour service REST
     *
     * @return SimpleXMLElement
     */
    public function getRooms()
    {
        $roomsTab = parent::getRooms();
        $rooms = simplexml_load_string('<rooms />');
        foreach ($roomsTab as $roomTab) {
            $room = $rooms->addChild('room');
            foreach ($roomTab as $key => $value) {
                $room->addChild($key, $value);
            }
        }
        return $rooms;
    }
    
    /**
     * Utilisation normale du service REST
     *
     * @param string $dateBegin
     * @param string $dateEnd
     * @return array
     */
    public function getReservations($dateBegin, $dateEnd)
    {
        $reservations = parent::getReservations($dateBegin, $dateEnd);
        if (!$reservations) {
            return array('msg' => 'Bad result', 'status' => self::STATUS_FAIL);
        }
        return $reservations;
    }
    
}
